<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>Alterar Usuários</title>
		<s:url value="/css/style.css" var="cssStyle"></s:url>
		<link rel="stylesheet" type="text/css" href="${cssStyle}" media="screen">

		<script type="text/javascript">
		$(document).ready(function(){
			
			$(".confirm").click(function(){
				var login = $("#idLogin").val();
				var nome  = $("#idNome").val();
				var email = $("#idEmail").val();
				var senha = $("#idSenha").val();

 				if(login!="", nome!="",
 				   email!="", senha!=""){
 					if(!confirm("Confirma Alteração do Usuário: "+login+"?")){
      					$("#loading").hide();
						$(".loadingImage").CenterIt();
						$(".loadingImage").hide();	
      					return false;
   					}
   				}	
			});

			$("#idForm").submit(function(){
				var login = $("#idLogin").val();
				var nome  = $("#idNome").val();
				var email = $("#idEmail").val();
				var senha = $("#idSenha").val();
						
				function IsValidEmail(email){
					var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
					return filter.test(email);
				}
 
				if(login==""){
					$("p").hide();
					$("#idLogin").after("<p style='color:red;'>Nome é obrigatório.</p>");
					$("#loading").hide();
					$(".loadingImage").CenterIt();
					$(".loadingImage").hide();	
					return false;
				}else{
					$("p").hide();
				}
				
				if(nome==""){
					$("p").hide();
					$("#idNome").after("<p style='color:red;'>Nome é obrigatório.</p>");
					$("#loading").hide();
					$(".loadingImage").CenterIt();
					$(".loadingImage").hide();	
					return false;
				}else{
					$("p").hide();
				}
				
				if(email==""){
					$("p").hide();
					$("#idEmail").after("<p style='color:red;'>Email é obrigatório.</p>");
					$("#loading").hide();
					$(".loadingImage").CenterIt();
					$(".loadingImage").hide();	
					return false;
				}else{
					// Valida a mascara do email...
					if(IsValidEmail(email)==false){
						$("p").hide();
						$("#idEmail").after("<p style='color:red;'>Email incorreto!</p>");
						$("#loading").hide();
						$(".loadingImage").CenterIt();
						$(".loadingImage").hide();	
						return false;
					}else{
						$("p").hide();
					}
				}
				
				if(senha==""){
					$("p").hide();
					$("#idSenha").after("<p style='color:red;'>Senha é obrigatório.</p>");
					$("#loading").hide();
					$(".loadingImage").CenterIt();
					$(".loadingImage").hide();	
					return false;
				}else{
					$("p").hide();
				}
			});
		});
		</script>
	</head>
	<body>		
		<s:form action="alterar-usuario" namespace="/" method="POST" id="idForm">	
			<s:hidden name="alterar.id"></s:hidden>
			<s:textfield label="login" name="alterar.login" disabled="true" id="idLogin"/>
			<s:textfield label="nome"  name="alterar.nmusuario" id="idNome"required="true"/>
			<s:textfield label="email" name="alterar.email" id="idEmail"required="true"/>
			<s:password label="senha" name="alterar.senha" id="idSenha"required="true"/>
			<s:checkbox label="Admin" name="alterar.indadministrador" cssClass="checkbx" labelposition="left" ></s:checkbox>
			<br/>
			<input value="Alterar" type="submit" class="confirm, botao">
			<input type="button" onclick="window.history.go(-1)" class="botao" value="Cancelar"/>
		</s:form>
	</body>
</html>